﻿<UserControl x:Class="FullDayStrategyPlugin.Realtime.ControlPanel"
   
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
			 mc:Ignorable="d"
			 
             xmlns:Converters="clr-namespace:Utils.Wpf.Converters;assembly=Utils"
             xmlns:UserControls="clr-namespace:Plugins.UserControls;assembly=Plugins"
             xmlns:Utils="clr-namespace:Utils.Wpf;assembly=Utils" xmlns:FD2="clr-namespace:FullDayStrategyPlugin"
             d:DataContext="{d:DesignInstance Type=FD2R:ControlPanelVM}"
			 
			 Utils:AnimatorOnVisibilityChange.AnimationType="Fade"
			 Utils:AnimatorOnVisibilityChange.Duration="1000"
			 
			 Background="#1F1F1F" >

	<UserControl.Resources>
		<ResourceDictionary>
			<Converters:BooleanNotConverter x:Key="BooleanNotConverter" />
			<Converters:NegatedBooleanToVisibilityConverter x:Key="NegatedBooleanToVisibilityConverter" />
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="pack://application:,,,/Plugins;component/PluginTheme.xaml" />
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</UserControl.Resources>

	<UserControl.IsEnabled>
		<Binding Path="IsBusy" Converter="{StaticResource BooleanNotConverter}" />
	</UserControl.IsEnabled>

	<!--<UserControl.Background>
		<StaticResource ResourceKey="GridBackground" />
	</UserControl.Background>-->

	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>

		<Border Grid.Row="0" BorderThickness="1,1,1,0" BorderBrush="{StaticResource ControlPanelLines}" CornerRadius="10,10,0,0" Background="#DCDCDC" >
			<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" >
				<TextBlock Grid.Row="0" Text="Full Day Strategy Realtime Plugin" Margin="3" Foreground="Black" FontWeight="Bold" />
				<Image Source="..\Resources\Info.ico" Margin="10,0,0,0" >
					<Image.ToolTip>
						<StackPanel>
							<TextBlock Foreground="Black" FontWeight="Bold" Text="Full Day Strategy Realtime Plugin" />
							<TextBlock Foreground="Black" >
								The main idea is to buy with the market opening, set a stop loss to cut loss and let benefits<LineBreak/>
								flow in the right direction. We expect that the profit in the right direction <LineBreak/>
								is bigger than the limitted loses when the direction of the market is the opposite
							</TextBlock>
						</StackPanel>
					</Image.ToolTip>
					<Image.Style>
						<Style>
							<Style.Triggers>
								<Trigger Property="Image.IsEnabled" Value="False" >
									<Setter Property="Image.Opacity" Value="0.5" />
								</Trigger>
							</Style.Triggers>
						</Style>
					</Image.Style>
				</Image>
			</StackPanel>
		</Border>
		<Border Grid.Row="1" BorderThickness="1" BorderBrush="{StaticResource ControlPanelLines}" Padding="6" CornerRadius="0,0,10,10" >
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="Auto" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="Auto" />
				</Grid.RowDefinitions>

				<!-- Preset Selector -->
				<Expander Grid.Column="0" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Presets" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<UserControls:PresetSelector DataContext="{Binding PresetSelectorVM}" IsSaveEnabled="{Binding IsEnabled, ElementName=ExecuteButton}" />
				</Expander>

				<!-- Separator -->
				<Border Grid.Column="1" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Stock Selection -->
				<Expander Grid.Column="2" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Stocks" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<UserControls:StockSelector Grid.Column="2" DataContext="{Binding StockSelectorVM}" />
				</Expander>

				<!-- Separator -->
				<Border Grid.Column="3" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Hour Limits -->
				<Expander Grid.Column="4" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Hours" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<UserControls:HourSelector DataContext="{Binding HourSelectorVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
				<Border Grid.Column="5" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Stock Parameters -->
				<Expander Grid.Column="6" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Fees" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<UserControls:StockParametersSelector DataContext="{Binding StockParametersSelectorVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
				<Border Grid.Column="7" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Parameters -->
				<Expander Grid.Column="8" IsExpanded="True" ExpandDirection="Left" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="Options" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<FD2:StrategyControl DataContext="{Binding StrategyControlVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
				<Border Grid.Row="0" Grid.Column="9" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Internal state -->
				<Expander Grid.Column="10" IsExpanded="False" ExpandDirection="Right" >
					<Expander.Header>
						<ItemsControl TextElement.FontSize="11" ItemsSource="State" Foreground="{StaticResource FontBrush}" Visibility="{Binding IsExpanded, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Expander}, AncestorLevel=1}, Converter={StaticResource NegatedBooleanToVisibilityConverter}}" />
					</Expander.Header>
					<ContentControl IsEnabled="{Binding StockSelectorVM.IsStockSelected}" >
						<FD2:InternalState DataContext="{Binding InternalStateVM}"/>
					</ContentControl>
				</Expander>

				<!-- Separator -->
				<Border Grid.Row="0" Grid.Column="11" BorderBrush="{StaticResource SelectedRowBrush}" BorderThickness="1" Margin="10,0,10,0" />

				<!-- Buttons -->
				<UniformGrid Rows="2" Columns="1" Grid.Row="0" Grid.Column="12" >
					<Button Command="{Binding RunStrategyCommand, UpdateSourceTrigger=PropertyChanged}" x:Name="ExecuteButton" >
						<Button.Style>
							<Style>
								<Style.Triggers>
									<Trigger Property="Button.IsEnabled" Value="False" >
										<Setter Property="Button.Opacity" Value="0.5" />
									</Trigger>
								</Style.Triggers>
							</Style>
						</Button.Style>
						<Image Source="..\Resources\ExecuteRealTime.ico" Stretch="None" Margin="18,0,18,0" />
						<Button.ToolTip>
							<StackPanel>
								<TextBlock Foreground="Black" FontWeight="Bold" Text="Exectute" />
								<TextBlock Foreground="Black" Text="Execute the current strategy with the selected parameters" />
							</StackPanel>
						</Button.ToolTip>
					</Button>

					<Button Command="{Binding StopStrategyCommand, UpdateSourceTrigger=PropertyChanged}" >
						<Button.Style>
							<Style>
								<Style.Triggers>
									<Trigger Property="Button.IsEnabled" Value="False" >
										<Setter Property="Button.Opacity" Value="0.5" />
									</Trigger>
								</Style.Triggers>
							</Style>
						</Button.Style>
						<Image Source="..\Resources\StopRealTime.ico" Stretch="None" Margin="18,0,18,0" />
						<Button.ToolTip>
							<StackPanel>
								<TextBlock Foreground="Black" FontWeight="Bold" Text="Exectute" />
								<TextBlock Foreground="Black" Text="Execute the current strategy with the selected parameters" />
							</StackPanel>
						</Button.ToolTip>
					</Button>
				</UniformGrid>
			</Grid>
		</Border>
	</Grid>
</UserControl>
